package com.reger.web.config;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.http.HttpMethod;

import com.reger.core.model.SysModel;
import com.reger.core.utils.ListUtils;

public class CorsProperties implements SysModel{
	 
	private static final long serialVersionUID = 1L;

	/**
	 * 匹配的请求参数，默认*
	 */
	private String pathPattern="*";

	/**
	 * 用来指定本次预检请求的有效期，单位为秒。默认值24小时
	 */
	private Long maxAge=24L*60*60;
	
	/**
	 * 允许跨域的域名
	 */
	private List<String> allowedOrigins=new ArrayList<>();
	
	/**
	 * 请求允许跨域的方法,默认HEAD，OPTIONS
	 */
	private Set<HttpMethod> allowedMethods=new HashSet<>(ListUtils.n(HttpMethod.HEAD,HttpMethod.OPTIONS).to());
	
	/**
	 * 允许跨域的请求头,默认值 Accept,Accept-Encoding,Accept-Language,Connection,Content-Length,Content-Type,Cookie,Host,Origin,Referer,User-Agent,timestamp,sign
	 */

	private Set<String> allowedHeaders=new HashSet<>(ListUtils.n("Accept,Accept-Encoding,Accept-Language,Connection,Content-Length,Content-Type,Cookie,Host,Origin,Referer,User-Agent,timestamp,sign,curPlatform".split(",")).to());
	
	/**
	 * 不允许跨域的请求头
	 */
	private Set<String> exposedHeaders=new HashSet<>();
	
	/**
	 * 手否接收Cookie，默认值是false
	 */
	private Boolean allowCredentials=false;

	public String getPathPattern() {
		return pathPattern;
	}

	public void setPathPattern(String pathPattern) {
		this.pathPattern = pathPattern;
	}

	public Long getMaxAge() {
		return maxAge;
	}

	public void setMaxAge(Long maxAge) {
		this.maxAge = maxAge;
	}

	public List<String> getAllowedOrigins() {
		return allowedOrigins;
	}

	public void setAllowedOrigins(List<String> allowedOrigins) {
		this.allowedOrigins = allowedOrigins;
	}

	public Set<HttpMethod> getAllowedMethods() {
		return allowedMethods;
	}

	public void setAllowedMethods(Set<HttpMethod> allowedMethods) {
		this.allowedMethods = allowedMethods;
	}

	public Set<String> getAllowedHeaders() {
		return allowedHeaders;
	}

	public void setAllowedHeaders(Set<String> allowedHeaders) {
		this.allowedHeaders = allowedHeaders;
	}

	public Set<String> getExposedHeaders() {
		return exposedHeaders;
	}

	public void setExposedHeaders(Set<String> exposedHeaders) {
		this.exposedHeaders = exposedHeaders;
	}

	public Boolean getAllowCredentials() {
		return allowCredentials;
	}

	public void setAllowCredentials(Boolean allowCredentials) {
		this.allowCredentials = allowCredentials;
	}
}